package com.controller.medical;

import com.comm.R;
import com.comm.vo.medicinevo.DrugAllView;
import com.comm.vo.DrugBillVo;
import com.service.medical.DrugService;
import com.service.medical.PurchaseService;
import io.swagger.annotations.*;
import org.apache.shiro.SecurityUtils;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@RequestMapping("/medicine/purchase")
@Api(value = "药品进销存模块",tags = "采购入库的所有接口API")
@ApiResponses({
        @ApiResponse(code=200,message="请求成功"),
        @ApiResponse(code=404,message="找不到页面"),
        @ApiResponse(code=405,message="请求方法错误"),
        @ApiResponse(code=500,message="后台服务错误")
})
public class PurchaseController {

    @Resource
    private DrugService drugService;

    @Resource
    private PurchaseService purchaseService;


    //查询药品信息(添加药品按钮)
    @RequestMapping(value = "/findDrugList", method = RequestMethod.GET)
    @ApiOperation(value = "查询药品信息", notes = "查询药品信息", httpMethod = "post", response = R.class)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "currentPage",value = "当前页",paramType = "query",dataType = "int",required = true),
            @ApiImplicitParam(name = "pageSize",value = "每页的条数",paramType = "query",dataType = "int",required = true),
            @ApiImplicitParam(name = "drugName", value = "药品名称", paramType = "query", dataType = "String", required = false),
            @ApiImplicitParam(name = "drugSort", value = "药品分类", paramType = "query", dataType = "String", required = false),
            @ApiImplicitParam(name = "status",value = "状态",paramType = "query",dataType = "int",required = false)
    })

    public R findDrugList(@ApiParam() int currentPage,int pageSize,String drugName, String drugSort,int status) {
        return drugService.findDrugList(currentPage,pageSize,drugName,drugSort,status);
    }

    //根据id查询药品信息
    @RequestMapping(value = "/findDrugById", method = RequestMethod.GET)
    @ApiOperation(value = "根据id查询药品信息",notes = "根据id查询药品信息",httpMethod = "GET", response = R.class)
    @ApiImplicitParam(name = "drug_id",value = "药品编号",paramType = "query",dataType = "String",required = false)
    public R findDrugById(String drug_id) {
        return drugService.findDrugById(drug_id);
    }

    //查询所有供应商名称
    @RequestMapping(value = "/findAllSupName", method = RequestMethod.GET)
    @ApiOperation(value = "查询所有供应商名称", notes = "查询所有供应商名称", httpMethod = "GET", response = R.class)
    public R findSupName() {
        return purchaseService.findAllSupName();
    }

    //查询当前用户名称
    @RequestMapping(value = "/findSysName", method = RequestMethod.GET)
    @ApiOperation(value = "查询当前用户名称", notes = "查询当前用户名称", httpMethod = "GET", response = R.class)
    public String findSysName() {
        String name = SecurityUtils.getSubject().getPrincipal().toString();
        System.out.println(name);
        return name;
    }


    //提交审核按钮
    @RequestMapping(value = "/SubmitCheck",method = RequestMethod.POST)
    @ApiOperation(value = "提交审核",notes = "提交审核",httpMethod = "POST", response = R.class)
    @ResponseBody
    public R SubmitCheck(@RequestBody DrugBillVo drugBillVo) {
        R r = new R();
        r.setCode(200);
        r.setMsg("添加成功！");
        return r;
    }

    //直接入库按钮
    @RequestMapping(value = "/inStock", method = RequestMethod.POST)
    @ApiOperation(value = "直接入库", notes = "直接入库", httpMethod = "post", response = R.class)
//    @ApiImplicitParams({
//            @ApiImplicitParam(name = "checker",value = "审核人",paramType = "query",dataType = "String",required = true),
//            @ApiImplicitParam(name = "checkTime",value = "审核日期",paramType = "query",dataType = "String",required = true),
//            @ApiImplicitParam(name = "status", value = "状态", paramType = "query", dataType = "String", required = false),
//            @ApiImplicitParam(name = "classify", value = "药品名称", paramType = "query", dataType = "String", required = false)
//
//    })

    @ResponseBody
    public R inStock(@RequestBody @ApiParam(name = "drugAllView",value = "订单实体",required = true)DrugAllView drugAllView) {
        R r = new R();
        r.setCode(200);
        r.setMsg("添加成功！");
        return r;
    }


}
